import type { DataGrid, Pagination } from '@/types/global';
import type { TableData } from '@arco-design/web-vue/es/table/interface';
import axios from 'axios';
import qs from 'query-string';

/**
* ${table.comment}创建请求
*/
export interface ${entity}CreateRequest {
<#list table.fields as field>
 <#if field.propertyName != "id">
  <#if field.propertyType == "String" || field.propertyType == "Date">
   ${field.propertyName}?: string;
  <#elseif field.propertyType == "Integer" || field.propertyType == "Long">
   ${field.propertyName}?: number;
  <#elseif field.propertyType == "Boolean">
   ${field.propertyName}?: boolean;
  <#else>
   ${field.propertyName}?: any;
  </#if>
 </#if>
</#list>
}

/**
* ${table.comment}更新请求
*/
export interface ${entity}UpdateRequest extends ${entity}CreateRequest {
id?: number;
}

/**
* ${table.comment}查询请求
*/
export interface ${entity}QueryRequest extends Pagination {
searchValue?: string;
<#list table.fields as field>
 <#if field.propertyType == "String" || field.propertyType == "Date">
  ${field.propertyName}?: string;
 <#elseif field.propertyType == "Integer" || field.propertyType == "Long">
  ${field.propertyName}?: number;
 <#elseif field.propertyType == "Boolean">
  ${field.propertyName}?: boolean;
 <#else>
  ${field.propertyName}?: any;
 </#if>
</#list>
}

/**
* ${table.comment}查询响应
*/
export interface ${entity}QueryResponse extends TableData {
<#list table.fields as field>
 <#if field.propertyType == "String">
  ${field.propertyName}: string;
 <#elseif field.propertyType == "Integer" || field.propertyType == "Long" || field.propertyType == "Date">
  ${field.propertyName}: number;
 <#elseif field.propertyType == "Boolean">
  ${field.propertyName}: boolean;
 <#else>
  ${field.propertyName}: any;
 </#if>
</#list>

}

/**
* ${apiComment.create}
*/
export function create${entity}(request: ${entity}CreateRequest) {
return axios.post('/${apiComment.ModuleName}/${apiComment.typeHyphen}/create', request);
}

/**
* ${apiComment.updateById}
*/
export function update${entity}(request: ${entity}UpdateRequest) {
return axios.put('/${apiComment.ModuleName}/${apiComment.typeHyphen}/update', request);
}

/**
* ${apiComment.getById}
*/
export function get${entity}(id: number) {
return axios.get<${entity}QueryResponse>('/${apiComment.ModuleName}/${apiComment.typeHyphen}/get', { params: { id } });
 }

 /**
 * ${apiComment.getByIdList}
 */
 export function batchGet${entity}List(idList: Array<number>) {
  return axios.get<${entity}QueryResponse[]>('/${apiComment.ModuleName}/${apiComment.typeHyphen}/batch-get', {
  params: { idList },
  paramsSerializer: params => {
  return qs.stringify(params, { arrayFormat: 'comma' });
  }
  });
  }

  /**
  * ${apiComment.queryList}
  */
  export function get${entity}List(request: ${entity}QueryRequest) {
  return axios.post<Array<${entity}QueryResponse>>('/${apiComment.ModuleName}/${apiComment.typeHyphen}/list', request);
   }

   /**
   * ${apiComment.queryPage}
   */
   export function get${entity}Page(request: ${entity}QueryRequest) {
   return axios.post<DataGrid<${entity}QueryResponse>>('/${apiComment.ModuleName}/${apiComment.typeHyphen}/query', request);
    }

    /**
    * ${apiComment.queryCount}
    */
    export function get${entity}Count(request: ${entity}QueryRequest) {
    return axios.post<number>('/${apiComment.ModuleName}/${apiComment.typeHyphen}/count', request);
     }

     /**
     * ${apiComment.deleteById}
     */
     export function delete${entity}(id: number) {
     return axios.delete('/${apiComment.ModuleName}/${apiComment.typeHyphen}/delete', { params: { id } });
     }

     /**
     * ${apiComment.batchDelete}
     */
     export function batchDelete${entity}(idList: Array<number>) {
      return axios.delete('/${apiComment.ModuleName}/${apiComment.typeHyphen}/batch-delete', {
      params: { idList },
      paramsSerializer: params => {
      return qs.stringify(params, { arrayFormat: 'comma' });
      }
      });
      }
